import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login.vue'
import store from './../store/index'
import FirstTable from "../components/backgroundCom/FirstTable";
import SecondTable from "../components/backgroundCom/SecondTable";
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
  },
  {
    path: '/front/index',//前台首页路由地址
    name: 'frontIndex',
    component: () => import('../views/frontDeskPage/index.vue'),
    meta: {
      isLogin: true,
      roles: ['admin'],//登录的用户权限，admin普通管理员
    },
    children: [
      {
        path: '/front/index',
        redirect: '/front/tableNav',
      },
      {
        path: '/front/tableNav',//前台餐桌子菜单路由地址
        name: 'tableNav',
        component: () => import('../components/frontDeskCom/tableNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],//登录的用户权限，admin普通管理员
        },
        children: [
          {
            path: '/front/tableNav',
            redirect: '/front/tableState',
          },
          {
            path: '/front/tableState',//前台餐桌状态路由地址
            name: 'tableState',
            component: () => import('../views/frontDeskPage/tableStatePage.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],//登录的用户权限，admin普通管理员
            }
          },
        ]
      },
      {
        path: '/front/orderNav',//前台餐桌点餐子菜单路由地址
        name: 'orderNav',
        component: () => import('../components/frontDeskCom/orderNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],//登录的用户权限，admin普通管理员
        },
        children: [
          {
            path: '/front/orderNav',
            redirect: '/front/tableOrder',
          },
          {
            path: '/front/tableOrder',//前台餐桌点餐路由地址
            name: 'tableOrder',
            component: () => import('../views/frontDeskPage/tableOrderPage.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],//登录的用户权限，admin普通管理员
            }
          },
        ]
      },
      {
        path: '/front/membersNav',//前台会员路子菜单由地址
        name: 'membersNav',
        component: () => import('../components/frontDeskCom/membersNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],//登录的用户权限，admin普通管理员
        },
        children: [
          {
            path: '/front/membersNav',
            redirect: '/front/addMembers',
          },
          {
            path: '/front/addMembers',//前台添加会员路由地址
            name: 'addMembers',
            component: () => import('../views/frontDeskPage/addMembersPage.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],//登录的用户权限，admin普通管理员
            }
          },
          {
            path: '/front/selectMembers',//前台查询会员路由地址
            name: 'selectMembers',
            component: () => import('../views/frontDeskPage/selectMembersPage.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],//登录的用户权限，admin普通管理员
            }
          },
        ]
      },
      {
        path: '/front/indentNav',//前台查询子菜单订单子菜单路由地址
        name: 'indentNav',
        component: () => import('../components/frontDeskCom/indentNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],//登录的用户权限，admin普通管理员
        },
        children: [
          {
            path: '/front/indentNav',
            redirect: '/front/selectOrder',
          },
          {
            path: '/front/selectOrder',//前台查询订单路由地址
            name: 'selectOrder',
            component: () => import('../views/frontDeskPage/selectOrderPage.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],//登录的用户权限，admin普通管理员
            }
          },
        ]
      },
      {
        path: '/front/invoicingNav',//前台结账路由子菜单地址
        name: 'invoicingNav',
        component: () => import('../components/frontDeskCom/invoicingNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],//登录的用户权限，admin普通管理员
        },
        children: [
          {
            path: '/front/invoicingNav',
            redirect: '/front/invoicing',
          },
          {
            path: '/front/invoicing',//前台结账路由地址
            name: 'invoicing',
            component: () => import('../views/frontDeskPage/invoicingPage.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],//登录的用户权限，admin普通管理员
            },
            children:[{
              path:'/front/invoicing/invoSelectVip',
              name:'vipInvoicing',
              component:()=>import('../components/frontDeskCom/invoSelectVip.vue'),
              meta: {
                isLogin: true,
                roles: ['admin'],//登录的用户权限，admin普通管理员
              }
            },
              {
                path:'/front/invoicing/invoSelectTableNo',
                name:'invoSelectTableNo',
                component:()=>import('../components/frontDeskCom/invoSelectTableNo.vue'),
                meta: {
                  isLogin: true,
                  roles: ['admin'],//登录的用户权限，admin普通管理员
                }
              },
              {
                path:'/front/invoicing/invoBuyOrder',
                name:'invoBuyOrder',
                component:()=>import('../components/frontDeskCom/invoBuyOrder.vue'),
                meta: {
                  isLogin: true,
                  roles: ['admin'],//登录的用户权限，admin普通管理员
                }
              },]
          },
        ]
      },
      {
        path: '/front/workNav',//前台员工工作信息子菜单路由地址
        name: 'workNav',
        component: () => import('../components/frontDeskCom/workNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],//登录的用户权限，admin普通管理员
        },
        children: [
          {
            path: '/front/workNav',
            redirect: '/front/staffWork',
          },
          {
            path: '/front/staffWork',//前台员工工作信息路由地址
            name: 'staffWork',
            component: () => import('../views/frontDeskPage/staffWorkPage.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],//登录的用户权限，admin普通管理员
            },
            children:[
              {
                path: '/front/staffWork',//前台员工工作信息路由地址
                redirect:'/front/staffWork/checkWorkArrange',

              },
              {
                path: '/front/staffWork/checkWorkArrange',//前台员工工作信息路由地址
                name: 'checkWorkArrange',
                component: () => import('../components/frontDeskCom/checkWorkArrange.vue'),
                meta: {
                  isLogin: true,
                  roles: ['admin'],//登录的用户权限，admin普通管理员
                }
              },
              {
                path: '/front/staffWork/checkSalary',//前台员工工作信息路由地址
                name: 'checkSalary',
                component: () => import('../components/frontDeskCom/checkSalary.vue'),
                meta: {
                  isLogin: true,
                  roles: ['admin'],//登录的用户权限，admin普通管理员
                }
              },
              {
                path: '/front/staffWork/checkAttendance',//前台员工工作信息路由地址
                name: 'checkAttendance',
                component: () => import('../components/frontDeskCom/checkAttendance.vue'),
                meta: {
                  isLogin: true,
                  roles: ['admin'],//登录的用户权限，admin普通管理员
                }
              },
            ]
          },
        ]
      },
    ]
  },
  {
    path: '/back/index',//后台首页路由地址
    name: 'backIndex',
    component: () => import('../views/backgroundPage/index.vue'),
    meta: {
      isLogin: true,
      roles: ['superAdmin', 'admin', 'accountAdmin'],
      //登录的用户权限，superAdmin超级管理员、admin普通管理员、accountAdmin会计
    },
    children: [
      {
        path: '/back/index',
        redirect: '/back/staffNav',
      },
      {
        path: '/back/staffNav',//后台员工信息子菜单路由地址
        name: 'staffNav',
        component: () => import('../components/backgroundCom/staffNav.vue'),
        meta: {
          isLogin: true,
          roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
        },
        children: [
          {
            path: '/back/staffNav',
            redirect: '/back/staffInformation'
          },
          {
            path: '/back/staffInformation',//后台员工信息路由地址
            name: 'staffInformation',
            component: () => import('../views/backgroundPage/staffInformationPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
          {
            path: '/back/staffPositions',//后台员工职位路由地址
            name: 'staffPositions',
            component: () => import('../views/backgroundPage/staffPositionsPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
          {
            path: '/back/staffPermissions',//后台员工权限路由地址
            name: 'staffPermissions',
            component: () => import('../views/backgroundPage/staffPermissionsPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
        ]
      },
      {
        path: '/back/cuisineNav',//后台菜品子菜单路由地址
        name: 'cuisineNav',
        component: () => import('../components/backgroundCom/cuisineNav.vue'),
        meta: {
          isLogin: true,
          roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
        },
        children: [
          {
            path: '/back/cuisineNav',
            redirect: '/back/foodsSet'
          },
          {
            path: '/back/foodsSet',//后台菜品设置路由地址
            name: 'foodsSet',
            component: () => import('../views/backgroundPage/foodsSetPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
          {
            path: '/back/foodsType',//后台菜品类别路由地址
            name: 'foodsType',
            component: () => import('../views/backgroundPage/foodsTypePage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
        ]
      },
      {
        path: '/back/consumablNav',//后台消耗品管理子菜单路由地址
        name: 'consumablNav',
        component: () => import('../components/backgroundCom/consumablNav.vue'),
        meta: {
          isLogin: true,
          roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
        },
        children: [
          {
            path: '/back/consumablNav',
            redirect: '/back/consumablesManagement'
          },
          {
            path: '/back/consumablesManagement',//后台消耗品管理路由地址
            name: 'consumablesManagement',
            component: () => import('../views/backgroundPage/consumablesManagementPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
          {
            path: '/back/consumablesType',//后台消耗品类型路由地址
            name: 'consumablesType',
            component: () => import('../views/backgroundPage/consumablesTypePage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
        ]
      },
      {
        path: '/back/operationNav',//后台员工排班管理子菜单路由地址
        name: 'operationNav',
        component: () => import('../components/backgroundCom/operationNav.vue'),
        meta: {
          isLogin: true,
          roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
        },
        children: [
          {
            path: '/back/operationNav',
            redirect: '/back/employeeScheduling'
          },
          {
            path: '/back/employeeScheduling',//后台员工排班管理路由地址
            name: 'employeeScheduling',
            component: () => import('../views/backgroundPage/employeeSchedulingPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
          {
            path: '/back/restaurantBusiness',//后台餐厅营业管理路由地址
            name: 'restaurantBusiness',
            component: () => import('../views/backgroundPage/restaurantBusinessPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
          {
            path: '/back/restaurantTable',//后台餐厅餐桌管理路由地址
            name: 'restaurantTable',
            component: () => import('../views/backgroundPage/restaurantTablePage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
          {
            path: '/back/restaurantMember',//后台餐厅会员管理路由地址
            name: 'restaurantMember',
            component: () => import('../views/backgroundPage/restaurantMemberPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'admin'], //登录的用户权限，superAdmin超级管理员、admin普通管理员
            },
          },
        ]
      },
      {
        path: '/back/moneyNav',//后台财务管理子菜单路由地址
        name: 'moneyNav',
        component: () => import('../components/backgroundCom/moneyNav.vue'),
        meta: {
          isLogin: true,
          roles: ['superAdmin', 'accountAdmin'], //登录的用户权限，superAdmin超级管理员、accountAdmin会计
        },
        children: [
          {
            path: '/back/moneyNav',
            redirect: '/back/financialManagement'
          },
          {
            path: '/back/financialManagement',//后台财务管理路由地址
            name: 'financialManagement',
            component: () => import('../views/backgroundPage/financialManagementPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'accountAdmin'], //登录的用户权限，superAdmin超级管理员、accountAdmin会计
            },
            children:[
              {
                path:'/back/financialManagement',
                redirect: '/back/FirstTable'
              },
              {
                path:'/back/FirstTable',
                name:'FirstTable',
                component:()=>import('../components/backgroundCom/FirstTable')
              },
              {
                path:'/back/SecondTable',
                name:'SecondTable',
                component:()=>import('../components/backgroundCom/SecondTable')
              }
            ]//两个表格
          },
          {
            path: '/back/costManagement',//后台成本管理路由地址
            name: 'costManagement',
            component: () => import('../views/backgroundPage/costManagementPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'accountAdmin'], //登录的用户权限，superAdmin超级管理员、accountAdmin会计
            },
          },
          {
            path: '/back/wageManagement',//后台工资管理路由地址
            name: 'wageManagement',
            component: () => import('../views/backgroundPage/wageManagementPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin', 'accountAdmin'], //登录的用户权限，superAdmin超级管理员、accountAdmin会计
            },
          },
        ]
      },
      {
        path: '/back/systemNav',//后台数据备份与还原子菜单路由地址
        name: 'systemNav',
        component: () => import('../components/backgroundCom/systemNav.vue'),
        meta: {
          isLogin: true,
          roles: ['superAdmin'], //登录的用户权限，superAdmin超级管理员
        },
        children: [
          {
            path: '/back/systemNav',
            redirect: '/back/dataManipulation'
          },
          {
            path: '/back/dataManipulation',//后台数据备份与还原路由地址
            name: 'dataManipulation',
            component: () => import('../views/backgroundPage/dataManipulationPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin'], //登录的用户权限，superAdmin超级管理员
            },
          },
          {
            path: '/back/staffOperationLog',//后台员工操作日志路由地址
            name: 'staffOperationLog',
            component: () => import('../views/backgroundPage/staffOperationLogPage.vue'),
            meta: {
              isLogin: true,
              roles: ['superAdmin'], //登录的用户权限，superAdmin超级管理员
            },
          },
        ]
      },
    ]
  },
]

const router = new VueRouter({
  //mode: 'history',
  base: process.env.BASE_URL,
  routes
});

router.beforeEach((to,from,next)=>{
  //console.log(to.meta.isLogin)
  if(to.meta.isLogin){
    //需要登录
    //判断系统是否登录
    //console.log(store.state.user)
    //console.log(store.state.user.userName)
    if(store.state.user.userName){
      //为true，代表登陆了
      next()
    }else {
      alert('请登录之后再操作！')
      router.push('/login')
    }
  }else {
    next()
  }
})

export default router
